import math
import sys

import pygame


def Angle(p1, p2):
    """ 弧度 3.14"""
    return math.atan2((p2[1] - p1[1]), (p2[0] - p1[0]))


def Radian(p1, p2):
    """ 角度 90. """
    return Angle(p1, p2) * (180 / math.pi)


def AnglePos(pos, _angle, r):
    return pos[0] + r * math.cos(_angle * math.pi / 180), pos[1] - r * math.sin(_angle * math.pi / 180)


events = []
target_position = (150, 150)
angle = 0
r = 100


def radar():
    global angle, r
    angle += 1
    group.empty()

    # if angle % 180 < 90:
    #     r -= .8
    # else:
    #     r += .8
    for x in range(0, int(r), 1):
        pos = AnglePos(target_position, angle, x)
        group.add(sp([int(pos[0]), int(pos[1])]))


class sp(pygame.sprite.Sprite):
    def __init__(self, pos):
        super().__init__()
        self.image = pygame.Surface([1, 1])
        self.rect = self.image.get_rect()
        self.image.fill([0, 255, 0])
        self.rect.center = pos


events += [radar]
pygame.init()
group = pygame.sprite.Group()

window = pygame.display.set_mode([300, 300])
clock = pygame.time.Clock()
t = 0

while True:
    window.fill("black")
    tick = clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    t += tick
    if t > 5:
        t = 0
        for _ in events:
            _()

    group.draw(window)
    group.update()
    pygame.display.update()
